# tuple: 元组。java中没有类似的数据结构
# 元组类似java中的数组，但是不允许修改，即元组是只读的
my_tuple: tuple[int, int, int, bool, str] = (1, 2, 3, True, 'hello')
print("my_tuple: ", my_tuple)
print("my_tuple数据类型", type(my_tuple))

tuple2 = (1,)  # 元组里只有一个元素时，加一个逗号
print("tuple2", tuple2)
print("tuple2数据类型", type(tuple2))

# 创建空元祖
tuple3 = tuple()  # tuple():类型转换
tuple4 = ()
print("tuple3", tuple3, "tuple4", tuple4)
print("tuple3和tuple4的数据类型", type(tuple3), type(tuple4))

# 类型转换
tuple5 = tuple('hello')  # str-->tuple
print("str -> tuple", tuple5)

str1 = str(tuple5)  # tuple-->str
print("tuple -> str", str1)

tuple6 = tuple([1, 2, 3, 4])  # list-->tuple
print("list -> tuple", tuple6)

list1 = list(tuple6)  # tuple-->list
print("tuple -> list", list1)

# 元祖的通用操作
print('-' * 30)
# 索引。索引从0开始
print("0索引处", my_tuple[0])
print("1索引处", my_tuple[1])
print("-1索引处", my_tuple[-1])

# len
print("len函数", len(my_tuple))

# max min
print("max和min", max(tuple6), min(tuple6))
# del
tuple5 = (1, 2, 3, 4, 5)
del tuple5
# print(tuple5)
# +
print(my_tuple + tuple6)
# *
print(my_tuple * 3)
# in
print(1 in my_tuple)

# 元组的常用方法
a = my_tuple.count('hellwwwo')
print(a)
print(my_tuple)
a = my_tuple.index(2)
print(a)

# 元组的遍历
print('-' * 30)
for i in my_tuple:
    print(i)

for index, value in enumerate(my_tuple):
    print(index, value)

for i in range(len(my_tuple)):
    print(i, my_tuple[i])
